package org.darack_application;

import java.net.URL;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import android.util.Log;

public class MThread extends Thread{
	ArrayList<String> th_iden_num,th_name,th_phone,th_email,th_workarea;
	public MThread(ArrayList<String> iden_num, ArrayList<String> name, ArrayList<String> phone, ArrayList<String> email, ArrayList<String> workarea){
		th_iden_num=iden_num;
		th_name=name;
		th_phone=phone;
		th_email=email;
		th_workarea=workarea;	
	}
	public void run(){
		try{
			URL text = new URL("http://hotsun0428.cafe24.com/Darack_Project/database_new.jsp");

			XmlPullParserFactory parserCreator = XmlPullParserFactory.newInstance();

			XmlPullParser parser = parserCreator.newPullParser();

			parser.setInput(text.openStream(),null);

			int parserEvent = parser.getEventType();
			String tag;
			boolean inTitle1 = false, inTitle2=false, inTitle3=false, inTitle4=false, inTitle5=false;
			while(parserEvent != XmlPullParser.END_DOCUMENT){
				switch(parserEvent){

				case XmlPullParser.START_TAG:
					tag=parser.getName();
					if(tag.compareTo("iden_num")==0){
						inTitle1=true;
					}else if(tag.compareTo("name")==0){
						inTitle2=true;
					}else if(tag.compareTo("phone")==0){
						inTitle3=true;
					}else if(tag.compareTo("email")==0){
						inTitle4=true;
					}else if(tag.compareTo("workarea")==0){
						inTitle5=true;
					}
					break;

				case XmlPullParser.TEXT:
					tag=parser.getName();
					if(inTitle1){
						String max = parser.getText();
						th_iden_num.add(max);
					}else if(inTitle2){
						String max = parser.getText();
						th_name.add(max);
					}else if(inTitle3){
						String max = parser.getText();
						th_phone.add(max);
					}else if(inTitle4){
						String max = parser.getText();
						th_email.add(max);
					}else if(inTitle5){
						String max = parser.getText();
						th_workarea.add(max);
					}
					break;

				case XmlPullParser.END_TAG:
					tag=parser.getName();
					if(tag.compareTo("iden_num")==0){
						inTitle1=false;
					}else if(tag.compareTo("name")==0){
						inTitle2=false;
					}else if(tag.compareTo("phone")==0){
						inTitle3=false;
					}else if(tag.compareTo("email")==0){
						inTitle4=false;
					}else if(tag.compareTo("workarea")==0){
						inTitle5=false;
					}					
					break;

				}
				parserEvent=parser.next();
			}

		}catch(Exception e){
			Log.e(" ","Error in network call",e);
		}

	}
}
